<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function(Blueprint $table)
        {
            $table->increments('id')->comment('主键，自增，订单id');
            $table->unsignedInteger('user_id')->comment('外键，订单所属用户id');
            $table->string('orderNum', 16)->comment('16位订单编号');
            $table->unsignedInteger('status_id')->comment('外键，订单状态id');
            $table->double('total')->comment('订单总额');
            $table->string('receiver', 50)->comment('本次订购收货人');
            $table->string('phone', 11)->comment('收货人联系方式');
            $table->string('postcode', 6)->comment('收货人所在地邮编');
            $table->string('deliverAddress', 150)->comment('收货地址');
            $table->timestamps();
        });

        Schema::table('orders', function($table)
        {
            $table->foreign('user_id')->references('id')->on('users');
            $table->foreign('status_id')->references('id')->on('orderStatus');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('orders');
    }
}
